<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

global $jbconfig;
$task = JRequest::getVar('layout');
echo $task;
defined('_JEXEC') or die('Retricted Access');
rendfield_JS();
global $option;
$Itemid = JRequest::getVar('Itemid', 0);
if(isset($this->goto_buynow) && $this->goto_buynow || JRequest::getVar('goto_buynow', 0)){?>
	<div class="messengers">
		<?php if ($task=='duplicate') echo JText::_('You have not any posting left'); else echo JText::_('You have no standard posting left');?>
		<br />
		<a class="button" href="<?php echo JRoute::_('index.php?option='.JBCOMNAME.'&view=japosts&layout=selectplan');?>" title="click here to buy now"><?php echo JText::_('Order Ads')?></a>
	</div>
<?php
	return ;
}
?>
<?php JHTML::_('behavior.modal', 'a.modal'); ?>
<?php

$user = JFactory::getUser();
JFilterOutput::objectHTMLSafe( $this->item );
JHTML::_('behavior.tooltip');
//$profile = getItemByFieldName('ja_profiles','user_id',$user->id);
//$profile = $profile[0];
?>

<script type="text/javascript" language="javascript">
//<![CDATA[
	max_location_selection = <?php echo  $jbconfig['posts']->get('maximum_locations',3);?>;
	max_category_selection = <?php echo  $jbconfig['posts']->get('maximum_cats',3);?>;
	
	function submitJob(pressbutton) {
		form = document.jobForm;
		var sum_location = cal_number_selection('location_id',child_location_id);
		var sum_category = cal_number_selection('cat_id',child_cat_id)
		//Check location selection
		if (sum_location > max_location_selection)
		{
			alert("<?php echo JText::_('Your selected location is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_locations',3).' selections)'; ?>");
			return;
		}
		
		
		
		//Check category selection
		if (sum_category > max_category_selection)
		{
			alert("<?php echo JText::_('Your selected category is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_cats',3).' selections)'; ?>");
			return;
		}
		
		var direct_url_obj = document.getElementById('apply_type1');
		if (direct_url_obj)
		if (direct_url_obj.checked)
			if (form.direct_url.value=='')
			{
				alert("<?php echo JText::_('Direct URL for apply could not be empty'); ?>");
				return;
			}
			
	    form.task.value = pressbutton;
	    form.submit();
		
	}
	
	function show_div_content(id){
	    var ele = document.getElementById(id);
	    if(ele.style != null){
	        ele.style.display = ele.style.display == 'none' ? 'block' : 'none';
	    }
	  
	}
	
	function select_jobtype(type)
	{
		form = document.jobForm;
		form.is_hotjob.value = type;
	}
	
	function select_direct_url(is_checked)
	{
		var s_direct_url = $('s_direct_url');
		if (is_checked)
		{
			
		s_direct_url.style.display='block';
		}
		else
		{
		s_direct_url.style.display='none';
		}
		
	}
	
	function user_profile_apply_url(text_url)
	{
		form = document.jobForm;
		form.direct_url.value = text_url;
		document.getElementById('sbox-window').close();
	}

//]]>
</script>

<div id="jobboard-content">
<form name="jobForm" class="form-validate" action="<?php echo JURI::root();?>index.php" method="post" enctype="multipart/form-data">    
    <?php 
    if ($task=='duplicate')
    {
    	
    ?>
    <h1 class="componentheading"><?php echo JText::_('Duplicate from job'); ?>&nbsp;<?php echo "'".$this->item->temp_title."'"; ?></h1>
		<?php
		if ($this->item->title!='') $this->item->title = JText::_('Copy of').' '.$this->item->title;
    }
    ?>
    <div class="moduletable job-box">
	
		<table class="tabledata jobdetails">
			<?php 
        	if ($task=='duplicate')
        	{
            ?>
			<tr>
				<td>
					<?php echo JText::_("Select Job Type"); ?>
				</td>
				<td>
					<input <?php echo $this->can_post_premium_job; ?> type="radio" name="job_type" value="1" <?php echo (($this->can_post_premium_job==''&&$this->item->is_hotjob)||($this->can_post_standard_job!=''))?'checked':''; ?> onclick="select_jobtype(this.value)"/> <?php echo JText::_('Premium job');?>
	        		<input <?php echo $this->can_post_standard_job; ?> type="radio" name="job_type" value="0" <?php echo (($this->can_post_standard_job==''&&!$this->item->is_hotjob)||($this->can_post_premium_job!=''))?'checked':''; ?> onclick="select_jobtype(this.value)"/> <?php echo JText::_('Standard job');?>
				</td>
			</tr>
			<?php 
        	}
        	?>
	        <?php
	        $k=0;
	        $action = (isset($this->item->id)&&($this->item->id!=0)&&($this->item->id!=null))?'edit':'new';
	        $firstIndex = findFirstField($this->item,$this->fieldlist,$action);
			$lastIndex = findLastField($this->item,$this->fieldlist,$action);
			for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ )
				if ($this->fieldlist[$i]->field_name!='direct_url')
				{
		            $field = $this->fieldlist[$i];
		            
		            if($field->display=='admin_only' && $user->aid<2) continue;
		            
		            $field_name = $field->field_name;
		            if($this->item->id && $task!='duplicate'){
		            	$input = rendfield($this->item, $field, false, TRUE, false);
		            }
		            else{
		            	$input = rendfield($this->item, $field, false, false, false);
		            }
		            
		            
		            if($field->field_type=='SEPERATOR' && $field->display!='hide_all'){?>
	    				</table>
					</div>
			    	<div class="moduletable jobdetails"> 
			  		<?php if($input!=''){?>
						<h3><?php echo $input;?></h3>
					<?php }?>
						<table class="tabledata jobdetails">
				    <?php }else{?>				
				           
					           	<?php if (isset($this->fieldlist[$i-1]))	{
							           	if (($i==$firstIndex)||($this->fieldlist[$i-1]->field_type=='SEPERATOR'))
								      		$classname = 'first sectiontableentry'.($k+1);
								      	elseif (isset($this->fieldlist[$i-1]))
								      	{
								      		if (isset($this->fieldlist[$i+1]) && ($i==$lastIndex)||(  isset($this->fieldlist[$i+1]->field_type) && $this->fieldlist[$i+1]->field_type=='SEPERATOR'))
									      		$classname = 'last sectiontableentry'.($k+1);
									      	else 
									      		$classname = 'sectiontableentry'.($k+1);
								      	}
								      	else 	
								      		$classname = 'last sectiontableentry'.($k+1);
					           	}
					           	else{     $classname = 'first sectiontableentry'.($k+1);}?>
					           	
					           	<?php if( ($action=='new' && $field->display=='hide_on_new') ||  ($field->display=='hide_all') ){?>
					           		<?php echo $input;?>
					           	<?php }else{?>				           	
						       		 <tr class="<?php echo $classname; ?>">
						                <td class="col1">
						                <?php echo JText::_($field->label); ?>:
						                </td>
						                
						                <td class="col2">
						                   <?php echo $input;?>
						                </td>
						            </tr> 
					            <?php }?>    
					             
					            <?php 					           
					            $k = 1 - $k;
	       			}
				}?>
				          
      	 </table> 
    </div>
	<table class="tabledata">
        <tr>
        	<td class="col1"></td>
            <td class="col2">
                <input class="button" type="button" onclick="submitJob('save');" value="<?php echo JText::_('Save'); ?>" />
                <a class="button" href="javascript:window.history.go(-1);"><?php echo JText::_('Back'); ?></a>
            </td>
        </tr>
    </table>
    
    <?php if(isset($this->appliedlist) && count($this->appliedlist)):?>
    <a href="javascript:show_div_content('applied-resumes');"><?php echo JText::_('Show/Hide'); ?></a>.
    <div id="applied-resumes" class="moduletable applied-resumes-box" style="display:block;">
	   	<h3>
	        <?php echo JText::_('Number of applications: '. count($this->appliedlist));?>
	    </h3>
	    <table class="tablelist applicationlist">
	        <thead>
	            <tr >
	                <td class="sectiontableheader"><?php echo JText::_('Subject')?></td>
	                <td class="sectiontableheader"><?php echo JText::_('Resume')?></td>
	                <td class="sectiontableheader"><?php echo JText::_('Attachment')?></td>
	                <td class="sectiontableheader"><?php echo JText::_('Applied Date/Time')?></td>
	            </tr>
	        </thead>
	        
		    <?php
		    $k = 1;
		    for($i = 0, $n = count($this->appliedlist); $i < $n; ++$i){
		        $application = $this->appliedlist[$i];
		        $k = 1- $k;
		        ?>
		        <tr class="<?php echo "row$k"; ?>">
		            <td><a target="_blank" href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&task=view&cid[]='. $application->id .'&fromsearch=2&Itemid='. $this->Itemid); ?>"><?php echo $application->title; ?></a></td>
		            <td><a target="_blank" href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaresumes&task=view&cid[]='. $application->resume_id .'&fromsearch=2&Itemid='. $this->Itemid); ?>"><?php echo JText::_('View resume'); ?></a></td>
		            <td>
		                <?php if($application->attachment):?>
		                <a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&task=download&fromsearch=2&cid[]='. $application->id .'&Itemid='. $this->Itemid); ?>"><?php echo JText::_('Download'); ?></a>
		                <?php endif; ?>
		            </td>
		            <td><?php echo $application->created_date; ?></td>
		        </tr>
		        <?php
		    }
		    ?>
    	</table>
    </div>
    <?php endif; ?>
    <?php
    if ((!$this->item->id))
    {
    ?>
    
    	<input type="hidden" name="created_date" value="<?php echo date("Y-m-d H:i:s") ?>" />
    	<?php if ($task!='duplicate') {?>
    	<input type="hidden" name="is_hotjob" value="0" />
    	<?php } else {?>
    	<input type="hidden" name="is_hotjob" value="<?php echo (($this->can_post_premium_job==''&&$this->item->is_hotjob)||($this->can_post_standard_job!=''))?'1':'0'; ?>" />
    	<?php } ?>
    <?php
    }
    elseif ($task!='duplicate') 
    {
    ?>
    	<input type="hidden" name="is_hotjob" value="<?php echo $this->item->is_hotjob; ?>" />
    <?php
    }
    ?>
    <input type="hidden" name="user_id" value="<?php echo $user->id; ?>" />
    <?php if ($task!='duplicate') { ?>
	<input type="hidden" name="cid[]" value="<?php echo $this->item->id?$this->item->id:JRequest::getInt('cid'); ?>" />
	<?php } ?><!--
	<input type="hidden" name="apply_url" value="<?php echo $profile->apply_url; ?>" />
    --><input type="hidden" name="posted" value="0" />
    <input type="hidden" name="temp_title" value="<?php echo isset($this->item->temp_title)?$this->item->temp_title:''; ?>" />
	<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
	<input type="hidden" name="view" value="jajobs" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="layout" value="<?php echo $this->getLayout(); ?>" />
    <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
    <input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
    <input type="hidden" name="is_frontend" value="1" />
    <?php echo JHTML::_( 'form.token' ); ?>	
 </form>
</div>